package area

import (
	"encoding/xml"
	"io/ioutil"
	"os"
)

type MapInfo struct {
	Mapinfo *Maps
}

type Region struct {
	Id     string  `xml:"id"`
	Top    float64 `xml:"top"`
	Left   float64 `xml:"left"`
	Buttom float64 `xml:"buttom"`
	Right  float64 `xml:"right"`
}

type Maps struct {
	Regions []Region `xml:"region"`
}

//加载地图信息
func (m *MapInfo) LoadMaps(path string) {
	file := path + "/map.xml"
	f, err := os.Open(file)
	if err != nil {
		panic(err)
	}

	defer f.Close()
	data, err := ioutil.ReadAll(f)
	if err != nil {
		panic(err)
	}
	var maps Maps
	err = xml.Unmarshal(data, &maps)
	if err != nil {
		panic(err)
	}

	m.Mapinfo = &maps
}

func CreateMap() *MapInfo {
	m := &MapInfo{}

	return m
}
